package com.example.demo.controller;

import com.example.demo.domain.Student;
import com.example.demo.services.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequestMapping("/student/list")
    public List<Student> studentlist() {
        return studentService.list();
    }

    @RequestMapping("/student/query/{id}")
    public List<Student> studentQuery(@PathVariable String id) {
        return studentService.query(Integer.parseInt(id));
    }

    @RequestMapping("/student/queryname/{name}")
    public List<Student> queryname(@PathVariable String name) {
        return studentService.queryname(name);
    }

    @DeleteMapping("/student/delete/{id}")
    public Integer deleteto(@PathVariable Integer id) {
        return studentService.deleteto(id);
    }

    @PostMapping("/student/insert/")
    public String insertto(@RequestBody Student student) {
        int result = studentService.insertto(student);
        if (result == 1) {
            return "success";
        } else {
            return "fail";
        }
    }
}
